<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		
		<div class="mui-content">
		    <ul class="mui-table-view">
		        <li class="mui-table-view-cell mui-media">
		            <a href="javascript:;" id="link_my_face">
		            	<span class="mui-pull-right mui-icon mui-icon-arrowright" style="line-height: 42px;color: lightgrey; margin-left: 3px;"></span>
		                <img class="mui-media-object mui-pull-right" id="img_my_face" src="../../css/registLogin/arrow.jpg">
		                <div class="mui-media-body" style="line-height: 42px;font-size: 16px;">
		                    头像
		                </div>
		            </a>
		        </li>
		        <li class="mui-table-view-cell mui-media">
		            <a href="javascript:;" id="link_my_nickname">
		                <span class="mui-pull-right mui-icon mui-icon-arrowright" style="color: lightgrey; margin-left: 3px;"></span>
		                <span id="span_nickname" class="mui-pull-right" style="color: grey;font-size: 14px;"></span>
		                <div class="mui-media-body">
		                    昵称
		                </div>
		            </a>
		        </li>
		        <li class="mui-table-view-cell mui-media">
		            <a href="javascript:;">
		            	<span id="span_username" class="mui-pull-right" style="color: grey;font-size: 14px;"></span>
		                <div class="mui-media-body">
		                    账号
		                </div>
		            </a>
		        </li>
		        <li class="mui-table-view-cell mui-media">
		            <a href="javascript:;" id="link_qrcode">
		            	<span class="mui-pull-right mui-icon mui-icon-arrowright" style="color: lightgrey; margin-left: 3px;"></span>
		                <img class="mui-media-object mui-pull-right" id="img_qrcode" src="../../image/qrcode.png" style="max-width: 20px;height: 20px;">
		                <div class="mui-media-body">
		                    二维码
		                </div>
		            </a>
		        </li>
		    </ul>
		    
		    <br />
		    <ul class="mui-table-view">
		    	<li class="mui-table-view-cell mui-media" style="text-align: center;">
		            <a id="link_logout" href="javascript:;">
		                <div class="mui-media-body">
		                    退出登录
		                </div>
		            </a>
		        </li>
		    </ul>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				//获得当前的webView
				var meWebView = plus.webview.currentWebview();
				meWebView.addEventListener("show", function() {
					refreshUserInfo();
				});
				
				//页面跳转我的头像
				var link_my_face = document.getElementById("link_my_face");
				link_my_face.addEventListener("tap", function() {
					if (plus.webview.getWebviewById("myFace.html") != null) {
						plus.webview.getWebviewById("myFace.html").reload();
					}
					mui.openWindow("myFace.html", "myFace.html");
				});
				
				
				//页面跳转昵称修改
				var link_my_nickname = document.getElementById("link_my_nickname");
				link_my_nickname.addEventListener("tap", function() {
					mui.openWindow("myNickname.html", "myNickname.html");
				});
				
				//二维码跳转
				var link_qrcode = document.getElementById("link_qrcode");
				link_qrcode.addEventListener("tap", function() {
					mui.openWindow("myQrcode.html", "myQrcode.html");
				});
				
				
				//用户退出
				var link_logout = document.getElementById("link_logout");
				link_logout.addEventListener("tap", function() {
					app.userLogout();
					mui.openWindow("../../login.html", "login.html");
				});
				
				//添加自定义事件刷新头像
				window.addEventListener("refresh", function() {
					refreshUserInfo();
				});
			});
			
			function refreshUserInfo() {
				var userInfo = app.getUserGlobalInfo();
				console.log(JSON.stringify(userInfo));
				if(userInfo != null) {
					var faceImg = userInfo.faceImage;
					var nickname = userInfo.nickname;
					var username = userInfo.username;
					var span_nickname = document.getElementById("span_nickname");
					var span_username = document.getElementById("span_username");
					
					span_nickname.innerHTML = nickname;
					span_username.innerHTML = username;
					//无头像时给予默认头像
					if(app.isNotNull(faceImg)) {
						var img_my_face = document.getElementById("img_my_face");
						img_my_face.src = app.fileUrl + faceImg;
					}
				}
				
			}
		</script>
	</body>

</html>